package com.qimou.iems.service.impl;

import com.qimou.iems.entity.PageArgs;
import com.qimou.iems.entity.PageList;
import com.qimou.iems.entity.QualityCategory;
import com.qimou.iems.mapper.IQualityCategoryMapper;
import com.qimou.iems.service.IQualityCategoryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Qimou Xie
 * @date 2018/6/3 21:25.
 **/
@Service
public class QualityCategoryServiceImpl implements IQualityCategoryService {

    @Resource
    private IQualityCategoryMapper qualityCategoryMapper;

    @Override
    public void save(QualityCategory qualityCategory) {
        qualityCategoryMapper.insert(qualityCategory);
    }

    @Override
    public void update(QualityCategory qualityCategory) {
        qualityCategoryMapper.update(qualityCategory);
    }

    @Override
    public List<QualityCategory> getQualityCategory(String categoryName) {
        Map<String,Object> map = new HashMap<String, Object>();
        map.put("categoryName",categoryName);
        map.put("pageArgs",null);
        return qualityCategoryMapper.selectQualityCategory(map);
    }

    @Override
    public PageList<QualityCategory> getQualityCategory(PageArgs pageArgs, Map<String, Object> map) {
        List<QualityCategory> qualityCategories = new ArrayList<QualityCategory>();
        Integer count = qualityCategoryMapper.countQualityCategory(map);
        if(null != count && count > 0){
            map.put("pageArgs",pageArgs);
            qualityCategories = qualityCategoryMapper.selectQualityCategory(map);
        }
        return new PageList<QualityCategory>(qualityCategories,count);
    }
}
